package club.bigtian.statusbar;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.util.Calendar;
import java.util.Date;

/**
 * 卡片列表对话框
 * 显示多个账户信息卡片
 */
public class CardListDialog extends DialogWrapper {

    private final Project project;
    
    public CardListDialog(@Nullable Project project) {
        super(project);
        this.project = project;
        setTitle("账户信息");
        init();
    }
    
    @Nullable
    @Override
    protected JComponent createCenterPanel() {
        JPanel mainPanel = new JPanel(new BorderLayout());
        // 使用默认背景色
        mainPanel.setBorder(JBUI.Borders.empty(15));

        // 创建网格布局面板 - 2列布局
        JPanel cardsPanel = new JPanel(new GridLayout(0, 2, 15, 15));
        // 使用默认背景色

        // 添加示例卡片数据
        cardsPanel.add(createSampleCard1());
        cardsPanel.add(createSampleCard2());
        cardsPanel.add(createSampleCard3());
        cardsPanel.add(createSampleCard4());

        // 包装到滚动面板
        JScrollPane scrollPane = new JScrollPane(cardsPanel);
        scrollPane.setBorder(null);
        scrollPane.setPreferredSize(new Dimension(800, 500));
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

        mainPanel.add(scrollPane, BorderLayout.CENTER);

        return mainPanel;
    }
    
    /**
     * 创建示例卡片1
     */
    private AccountCard createSampleCard1() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, 6);
        Date expireDate = cal.getTime();
        
        return new AccountCard(
            "d9.api.augmentcode.com",
            "aug****08@goodsniubi.space",
            expireDate,
            34000,
            "正常"
        );
    }
    
    /**
     * 创建示例卡片2
     */
    private AccountCard createSampleCard2() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, 15);
        Date expireDate = cal.getTime();
        
        return new AccountCard(
            "api.openai.com",
            "user****@example.com",
            expireDate,
            15000,
            "正常"
        );
    }
    
    /**
     * 创建示例卡片3
     */
    private AccountCard createSampleCard3() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, 2);
        Date expireDate = cal.getTime();

        return new AccountCard(
            "api.anthropic.com",
            "test****@demo.com",
            expireDate,
            2500,
            "即将过期"
        );
    }

    /**
     * 创建示例卡片4
     */
    private AccountCard createSampleCard4() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, 20);
        Date expireDate = cal.getTime();

        return new AccountCard(
            "d20.api.augmentcode.com",
            "demo****@test.space",
            expireDate,
            45000,
            "正常"
        );
    }
    
    @Override
    protected Action[] createActions() {
        // 只显示关闭按钮
        return new Action[]{getOKAction()};
    }
}

